//
//  SearchAddVC.m
//  BrushFace
//
//  Created by timer_q on 16/1/25.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "SearchAddVC.h"
#import "ContactViewModel.h"
#import "MySceneModel.h"
#import "AlertDialogHelper.h"

@interface SearchAddVC ()

@property (nonatomic,strong)ContactViewModel *reqmodel;
@property (nonatomic,strong)MySceneModel *myreqModel;
@end

@implementation SearchAddVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navBar setTitle:@"朋友验证"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 60, 44)];
    [button setTitle:@"发送" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.navBar setRightView:button];
    
    _reqmodel = [ContactViewModel SceneModel];
    _myreqModel = [MySceneModel SceneModel];
    
    [_myreqModel user_getMyIndexForAppAndCB:^(id output) {
        _textfield.text = [NSString stringWithFormat:@"%@：我是%@",output[@"nickname"],output[@"fullname"]];
    }];
    
}
- (void)rightBtnClick{
    __block SearchAddVC *blockSelf = self;
    [_reqmodel addFriendWithFriendID:self.userid andMessage:self.textfield.text andSource:@"1" andCB:^(id output) {
        if ([[NSString stringWithFormat:@"%@",output[@"result"]] integerValue]==1) {
            [AlertDialogHelper showToast:@"发送成功"];
            [blockSelf.navigationController popViewControllerAnimated:YES];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:output[@"errormsg"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
